class Login{
    constructor(){
        this.btn=document.querySelector('.submit_login') //登陆按钮
        this.init()
    }
    init(){
        this.btn.onclick=async ()=>{
    
            let phone=document.querySelector('#phone').value,
            password=document.querySelector('#password').value
            
            //用户名或密码没有输入
            if(!phone||!password){
                // console.log(111);
               let warn1=document.querySelector('.warn1')
               this.animation(warn1)
            }else{
                let res=await axios.get(`http://localhost:1998/user`)
                res=res.data
                console.log(res);
                let has=res.some(item=>{
                    return item.phone==phone&&item.password==password
                })
                if(!has){
                    //用户名密码不对
                    let warn3=document.querySelector('.warn3')
                    this.animation(warn3)
                }else{
                    //用户名和密码正确
                    let warn2=document.querySelector('.warn2')
                    this.animation(warn2)
                    //将用户名存入cookie
                    document.cookie=`user=${phone}`
                    //跳转首页
                    location.href="http://localhost:4023/index.html"
                }
            }
        
        
            
        }
    }
    //tips动画
    animation(ele){
       ele.style.opacity=1
        let timer=setInterval(() => {
        if(ele.style.opacity==0){
             clearInterval(timer)
       }else{
            ele.style.opacity-=0.02
      }  
   }, 10);
}
}

new Login()




